{template 'common/header'}
<div class="panel we7-panel ng-scope" >
	<div class="panel-heading">添加产品</div>
	<div class="panel-body we7-padding">
		<div class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">产品名称</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="goodsname" name="goodsname" value="{$goods['goodsname']}">
				</div>
		 	</div>
	        <div class="form-group">
	            <label class="col-sm-2 control-label">所属分类</label>
	            <div class="col-sm-8">
	                <select class="form-control required" placeholder="所属分类" id="classid" name="classid">
	                {loop $class $k $c}
	                    <option value="{$c['id']}" {if $c['id']==$goods['tid']}checked="checked"{else}{/if}>{$c['categoryname']}</option>                
	                {/loop}
	                </select>
	            </div>
	        </div> 	 		
			<div class="form-group">
				<label class="col-sm-2 control-label">产品缩略图</label>
				<div class="col-sm-8">
					  {php echo tpl_form_field_image('titlepic',$goods['titlepic']);}
				</div>
		 	</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">产品价格</label>
				<div class="col-sm-8">
					<input type="number" class="form-control" id="price" name="price" value="{$goods['price']}">
				</div>
		 	</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">产品排序</label>
				<div class="col-sm-8">
					<input type="number" class="form-control" id="orderid" name="orderid" value="{$goods['orderid']}">
				</div>
		 	</div>		 			 	
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">产品状态</label>
				<div class="col-xs-12 col-sm-8">
					<label class="radio radio-inline">
						<input type="radio" name="grounding" id="grounding" value="0" {if intval($goods['grounding']) != '1'}checked="checked"{/if}> 下架
					</label>
					<label class="radio radio-inline">
						<input type="radio" name="grounding" id="grounding" value="1" {if intval($goods['grounding']) == '1'}checked="checked"{/if}> 上架
					</label>
				</div>
			</div>	
			<div class="form-group">
				<label class="col-sm-2 control-label">产品简介</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="summary" name="symmary" value="{$goods['summary']}">
				</div>
		 	</div>				 	
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">产品图集</label>
				<div class="col-sm-8">
					{php echo tpl_form_field_multi_image('pics',$pics);}
				</div>
			</div>		 	
			<div class="form-group">
				<label class="col-sm-2 control-label">产品详情</label>
				<div class="col-sm-8">
					{php echo tpl_ueditor('details',$goods['details']);}
					<span class="help-block">&nbsp;&nbsp;小程序仅支持文本和图片排版</span>	
				</div>
		 	</div>
			<button type="button" id="save_goods" class="btn btn-info" style="display: block; margin-left: auto;margin-right: auto;">提交保存</button>
		</div>
	</div>	
</div>
<style type="text/css">.right-content{padding: 0;}</style>
<link rel="stylesheet" href="{MODULE_URL}public/css/Toast.css">
<script src="{MODULE_URL}public/js/Toast.js"></script>
<script type="text/javascript">
	$("#save_goods").on(
    	"click",function(){
    	var id = '{$gid}';
    	var goodsname = $.trim($('#goodsname').val());	
		var classid = $.trim($('#classid option:selected').val());
		var titlepic = $.trim($('input[name="titlepic"]').val());
		var price = $.trim($('#price').val());
		var summary = $.trim($('#summary').val());
		var picArr = $('input[name="pics[]"]').map(function(){return $(this).val()}).get();
	    var pics = picArr.join(','); 
		var ue=UE.getEditor('details'); 
		var details=ue.getContent();
		var grounding = $.trim($('input[name="grounding"]:checked').val());
		var orderid = $.trim($('#orderid').val()); 
	    if(goodsname==''){
	    	mqToast({type:1,context: '请填写产品名称'});
	    	return false;
	    }
	    if(classid==''){
	    	mqToast({type:1,context: '请选择所属分类'});
	    	return false;
	    }
	    if(titlepic==''){
	    	mqToast({type:1,context: '请上传产品略缩图'});
	    	return false;
	    }
	    if(price=='' || isNaN(price)){
	    	mqToast({type:1,context: '产品价格填写错误'});
	    	return false;
	    }
	    if(picArr==''){
	    	mqToast({type:1,context: '请上传产品图集，至少一张'});
	    	return false;

	    }
	    if(details==''){
	    	mqToast({type:1,context: '请填写产品详情'});
	    	return false;
	    }	
		$.ajax({
			url:"{php echo $this->createWebUrl('save_goodsedit');}&version_id="+"{$_GPC['version_id']}",
			data:{id:id,goodsname:goodsname,classid:classid,titlepic:titlepic,price:price,summary:summary,pics:pics,grounding:grounding,orderid:orderid,details:details},
			dataType:"json",
			type:"post",
			success:function(res){
				if(res.status==1){
					mqToast({type:1,context:res.msg});	
					return false;
				}else{
					mqToast({type:2,context:res.msg});
					return false;
				}
			}
		});		    
    });

</script>

{template 'common/footer'}